package com.yun.zf.admin.controller;

import com.yun.zf.system.service.SysActivityService;
import com.yun.zf.system.service.SysCouponService;
import com.yun.zf.common.admin.model.activity.ActivityAddMo;
import com.yun.zf.common.admin.model.activity.CouponAddMo;
import com.yun.zf.common.annotation.LogPrint;
import com.yun.zf.common.vo.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "活动优惠券管理")
@RestController
public class ActivityCouponController {
    @Autowired
    private SysActivityService activityService;
    @Autowired
    private SysCouponService couponService;

    @PostMapping("/addOneActivity")
    @PreAuthorize("@ss.hasAnyRoles('manager')")
    @ApiOperation(value = "新增活动")
    @LogPrint(description = "新增活动")
    public Response  addOneActivity(@Validated @RequestBody ActivityAddMo activityAddMo){
       int count = activityService.addOneActivity(activityAddMo);
        if (count>0){
            return  Response.success("活动添加成功");
        }
        return  Response.error("活动添加失败");
    }

    @PostMapping("/addCoupon")
    @PreAuthorize("@ss.hasAnyRoles('manager')")
    @ApiOperation(value = "新增优惠券")
    @LogPrint(description = "新增优惠券")
    public Response  addCoupon(@Validated @RequestBody CouponAddMo couponAddMo){
        int count =couponService.addCoupon(couponAddMo);
        if (count>0){
            return  Response.success("优惠券添加成功");
        }
        return  Response.error("优惠券添加失败");
    }


}
